﻿using System;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Reflection;
namespace Data
{
	 	//SF_help_cont
		public class SF_help_cont
	{	
		/// <summary>
        /// 主键
        /// </summary>
        private readonly string primaryKey= "Id";
		/// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public long Add(Model.SF_help_cont model)
        {
            return new DataAccess().Add<Model.SF_help_cont>(model, primaryKey);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Model.SF_help_cont model)
        {
            return new DataAccess().Update<Model.SF_help_cont>(model, primaryKey);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool Delete(long Id)
        {
            return new DataAccess().Delete<Model.SF_help_cont>(Id, primaryKey);
        }
        /// <summary>
        /// 单条
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Model.SF_help_cont GetModel(long Id)
        {
            return new DataAccess().Get<Model.SF_help_cont>(Id, primaryKey);
        }
        /// <summary>
        /// 总数据数
        /// </summary>
        /// <returns></returns>
        public int GetAll_Count()
        {
            return new DataAccess().GetCount<Model.SF_help_cont>(primaryKey);
        }
        /// <summary>
        /// 抽取分页数据
        /// </summary>
        public List<Model.SF_help_cont> GetPageList_Where(int PageIndex, int PageSize, string classid,out int totalCount)
        {          
            string strWhere = GetSqlWhere(classid);
            totalCount = new DataAccess().GetCount<Model.SF_help_cont>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.SF_help_cont>(PageIndex, PageSize, primaryKey, primaryKey+" desc", strWhere);
        }
        /// <summary>
        /// 抽取id从1到15的分页数据
        /// </summary>
        public List<Model.SF_help_cont> GetPageList_Whereby(int PageIndex, int PageSize, string sql, out int totalCount)
        {
            string strWhere = GetSqlWhereby(sql);
            totalCount = new DataAccess().GetCount<Model.SF_help_cont>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.SF_help_cont>(PageIndex, PageSize, primaryKey, primaryKey, strWhere);
        }
        /// <summary>
        /// 拼接条件
        /// </summary>
        public string GetSqlWhereby(string sql)
        {
            StringBuilder sqlWhere = new StringBuilder();

            sqlWhere.Append(" 1>0");

            if (!string.IsNullOrEmpty(sql) && !string.IsNullOrEmpty(sql.Trim()))
            {
                sqlWhere.Append(" and id between 1 and 15 ");
            }
            return sqlWhere.ToString();
        }
        /// <summary>
        /// 拼接条件
        /// </summary>
        public string GetSqlWhere(string classid)
        {
            StringBuilder sqlWhere = new StringBuilder();

            sqlWhere.Append(" 1>0");

            if (!string.IsNullOrEmpty(classid) && !string.IsNullOrEmpty(classid.Trim()))
            {
                sqlWhere.Append(" and classid like '%" + classid + "%'");
            }         
            return sqlWhere.ToString();
        }
        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public int Drop(string Ids)
        {
            return new DataAccess().Drop<Model.SF_help_cont>(Ids, primaryKey);
        }

        public List<Model.SF_help_cont> GetByClassid(long classid)
        {
            if (classid > 0)
            {
                return new DataAccess().GetList<Model.SF_help_cont>("SELECT * FROM SF_help_cont WHERE classid=" + classid);
            }            
            return null;           
        }
	}
}